﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils
{
    public static class LinqExtensions
    {
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            if (source == null)
            {
                throw new ArgumentException("source is null");
            }
            if (action == null)
            {
                throw new ArgumentException("action is null");
            }
            foreach (var element in source)
            {
                action(element);
            }
        }

        public static string ToString<T>(this IEnumerable<T> source, string sepatator)
        {
            if (source == null)
            {
                throw new ArgumentException("source is null");
            }
            if (sepatator == null)
            {
                throw new ArgumentException("sepatator is null");
            }
            var stringBuilder = new StringBuilder();

            foreach (var element in source)
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(sepatator);
                }
                stringBuilder.Append(element.ToString());
            }

            return stringBuilder.ToString();
        }
     }
}
